package org.cable.link.strategy;

import com.baomidou.mybatisplus.extension.api.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author hsj
 * @date 2023/10/30 15:24
 */
public class ShardingDBConfig {


    /**
     * 存储数据库位置编号
     */
    public static final List<String> dbPrefixList = new ArrayList<>();


    //配置启用哪些库的前缀
    static {
        dbPrefixList.add("0");
        dbPrefixList.add("1");
        dbPrefixList.add("a");
    }

    private static Random random = new Random();

   /** 随机 0  1  2*/
    public static String getRandomDbPrefix(String code) {
         /**每个code的hash值是固定的*/
        int hashCode = code.hashCode();
        int index =  Math.abs(hashCode) % dbPrefixList.size();


        return dbPrefixList.get(index);
    }



}
